package com.yijiajiao.finance.service.subaccount;

import com.yijiajiao.finance.bean.FinanceLog;
import com.yijiajiao.finance.mappers.FinanceLogMapper;
import com.yijiajiao.finance.mappers.TeacherMoneyMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.yijiajiao.finance.util.Config.O_PERCENTAGE;
import static com.yijiajiao.finance.util.Config.PERCENTAGE;

/**
 * @AUTHOR zhaoming@eduspace
 * @CREATE 2017-05-08-10:28
 */
public class WareSubAccount extends SubAccount{

    private TeacherMoneyMapper teacherMoneyMapper;
    private static Logger log = LoggerFactory.getLogger(WareSubAccount.class);
    public WareSubAccount(FinanceLogMapper financeLogMapper, TeacherMoneyMapper teacherMoneyMapper) {
        super(financeLogMapper);
        this.teacherMoneyMapper = teacherMoneyMapper;
    }

    @Override
    public void subAccount(FinanceLog financeLog) {
        financeLog.setTeacherIncome(financeLog.getTotalPrice().multiply(PERCENTAGE));
        financeLog.setSystemIncome(financeLog.getTotalPrice().multiply(O_PERCENTAGE));
        if (financeLog.getCurriculumType() != 2 && financeLog.getCurriculumType() != 6){//视频课和名家开讲不涉及到退款
            log.info("涉及退款，存入ariableMoneyChange="+financeLog.getTeacherIncome());
            financeLog.setVariableMoneyChange(financeLog.getTeacherIncome());
        } else {
            log.info("不涉及退款，存入withdrawalcahs="+financeLog.getTeacherIncome());
            financeLog.setWithdrawalCashChange(financeLog.getTeacherIncome());
        }
        //修改教师金额账户
        saveOrUpdateMoney(financeLog, teacherMoneyMapper, log);
        financeLogMapper.saveFinanceLog(financeLog);
    }

}
